﻿using System;
using MemoryPack;

namespace Hsenl {
    // 给子节点取反
    [Serializable]
    [MemoryPackable]
    public partial class InverseNode<TManager, TNode> : DecoratorNode<TManager, TNode> 
        where TManager : class, IBehaviorTree 
        where TNode : class, INode {
        protected override bool OnNodeEvaluate() {
            return this.Child != null;
        }
        
        protected override NodeStatus OnNodeTick() {
            var status = this.Child.TickNode();
            switch (status) {
                case NodeStatus.Success:
                    return NodeStatus.Failure;
                
                case NodeStatus.Failure:
                    return NodeStatus.Success;
                
                default:
                    throw new ArgumentOutOfRangeException($"OnNodeTick can't return {status}");
            }
        }
    }

    [Serializable]
    [MemoryPackable]
    public partial class InverseNode : InverseNode<IBehaviorTree, INode> { }
}